var time;
var grid;
efform_onload = function ()
{
	if($('#flag').val()==6)
	{
	   document.getElementById('ef_region_inqu').style.display = "none";
	}
	$('#ef_grid_result-0-fdDepartmentId').val($('#fdDepartmentId').val());
};  
button_query_onclick = function (){
	efgrid.submitInqu( "ef_grid_result", "ZM","ZMCG72","query");
}
button_insert_onclick = function (){
var status=$('#inqu_status1-0-fdStatus').val();
//中断时间计算	
	var endTime = $('#inqu_status1-0-fdOverTime').val();//完成时间
	end_str = (endTime).replace(/-/g,"/");
	var end_date = new Date(end_str);
	
	var staTime = $('#inqu_status1-0-fdHappenTime').val();//发生时间
	sta_str = (staTime).replace(/-/g,"/");
	var sta_date = new Date(sta_str);
    
	time = end_date-sta_date;
	if(time <= 0)
	{
	alert("处理完成时间不能早于或等于发生时间");return;
	}
	calcTime();
//		var zdTime = MillisecondToDate(time);
//		$('#inqu_status1-0-fdOffTime').val(time);
	
//非空校验	
	var ei_info=new EiInfo();
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][3].trim()==""){
		EFAlert("发生时间不能为空");
		return;
	}
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][6].trim()==""){
		EFAlert("发生地点不能为空");
		return;
	}
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][4].trim()==""){
		EFAlert("处理完成时间不能为空");
		return;
	}
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][2].trim()==""){
		EFAlert("责任单位不能为空");
		return;
	}
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][8].trim()==""){
		EFAlert("事故内容不能为空");
		return;
	}
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][9].trim()==""){
		EFAlert("事故影响不能为空");
		return;
	}
	
	var info = getDetail("ef_region_inqu1","inqu_status1");
	if (null != info) { 
		EiCommunicator.send("ZMCG72", "insert", info, ajax_callbackconfirm);
	} 
	window.location.reload(); 
}
button_update_onclick = function (){ 
	var status=$('#inqu_status1-0-fdStatus').val();
//中断时间计算	
	var endTime = $('#inqu_status1-0-fdOverTime').val();//完成时间
	end_str = (endTime).replace(/-/g,"/");
	var end_date = new Date(end_str);
	
	var staTime = $('#inqu_status1-0-fdHappenTime').val();//发生时间
	sta_str = (staTime).replace(/-/g,"/");
	var sta_date = new Date(sta_str);
    
	time = end_date-sta_date;
	if(time <= 0)
	{
	alert("处理完成时间不能早于或等于发生时间");return;
	}
	calcTime();
//	var zdTime = MillisecondToDate(time);
//	$('#inqu_status1-0-fdOffTime').val(time);
	
//非空校验	
	var ei_info=new EiInfo();
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][3].trim()==""){
		EFAlert("发生时间不能为空");
		return;
	}
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][6].trim()==""){
		EFAlert("发生地点不能为空");
		return;
	}
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][4].trim()==""){
		EFAlert("处理完成时间不能为空");
		return;
	}
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][2].trim()==""){
		EFAlert("责任单位不能为空");
		return;
	}
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][8].trim()==""){
		EFAlert("事故内容不能为空");
		return;
	}
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][9].trim()==""){
		EFAlert("事故影响不能为空");
		return;
	}
	
	if(status == "上报")
		{
		alert("只能上报草拟的记录");return;
		}
	
	var info = getDetail("ef_region_inqu1","inqu_status1");
	if (null != info && status != "上报") {
		EiCommunicator.send("ZMCG72", "update", info, ajax_callbackconfirm);
	} 
	window.location.reload(); 
}
button_delete_onclick = function (){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return;  
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r){
			efgrid.submitForm( "ef_grid_result", "ZM","ZMCG72","delete",true);
		}
	}); 
}  
//	var grid=isSelected("ef_grid_result");
//	if (grid == 0)return; 
//	var rows=grid.getCheckedRows();
//	for(var i=0;i<rows.length;i++)
//	{
//		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
//		{
//			EFAlert("只能对草拟的记录进行删除！"); return;
//		}
//
//	}
//	EFConfirm('你确认要删除吗?', '确认框', function(r) {
//		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCG72","delete",true);
//	});
//}
button_report_onclick = function (){
	
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	EFConfirm('你确认要上报吗?', '确认框', function(r) {
		if(r){
	        efgrid.submitForm( "ef_grid_result", "ZM","ZMCG72","report",true);
		}
	}); 
}  
var ajax_callbackconfirm = {
	onSuccess : function(eiInfo) {
		efwindow.hide(); 
		var grid = efgrid.getGridObject("ef_grid_result");
		grid.refresh(eiInfo);
	}, 
	onFail:function(eMsg)
	{
		alert("确认失败，原因："+eMsg);
	}
}

efgrid_onRowClicked = function( grid_id, row_index ){
	
	
	if(grid_id == "ef_grid_result"){ 
		 grid = efgrid.getGridObject(grid_id);
		var fdStatus=grid.getCellValueByColumnName(row_index,"fdStatus");

		var selectedRow=grid.getRowData(row_index);
		for(var item in selectedRow){
			var colname=item;
			var colvalue=selectedRow[item];
			$('#ef_region_inqu1').find('#inqu_status1-0-'+colname).val(colvalue);
		} 
	}
}

var hideAndShowSubButtons=function(status)
{
	if(!status)
	{
		efbutton.setButtonStatus("insert", false);
		efbutton.setButtonStatus("update", false);
	}else
	{
		efbutton.setButtonStatus("insert", true);
		efbutton.setButtonStatus("update", true);
	}
}

//function MillisecondToDate(msd) {
//    var time = parseFloat(msd) / 1000;
//            time = parseInt(time / 3600.0) + "小时" + parseInt((parseFloat(time / 3600.0) -
//                parseInt(time / 3600.0)) * 60) + "分钟" +
//                parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) -
//                parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + "秒";
//    return time;
//}

calcTime = function(){
	  time = parseFloat(time) / 1000;
      time = parseInt(time / 3600.0) + "小时" + parseInt((parseFloat(time / 3600.0) -
      parseInt(time / 3600.0)) * 60) + "分钟" +
      parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) -
      parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + "秒";

      $('#inqu_status1-0-fdOffTime').val(time);
//    return time;
}
